'''
These codes are for F.L.
1. exec SQL query words.
2. get results.
3. request url.
'''

import os
import pycurl
import cx_Oracle
from io import BytesIO

'''
I do not know how to exec Oracle's SQL query words in Linux.
But I think it's easy.
So I give sample codes here.
'''

#if you need system call, just use this as shell
#os.system("SQL querys > result")

#call SQL proc, if you have question, just search "python oracle"
username = "aa"
userpwd = "bb"
dbname = "cc"
host="db.com"
port = 1521

dsn=cx_Oracle.makedsn(host, port, dbname)
conn = cx_Oracle.connect(username, userpwd, dsn)
cur = conn.cursor()

PARA_A = None#入参
PARA_B = None#入参
PARA_C = '123'#入参
PARA_D = cur.var(cx_Oracle.NUMBER)#返回值
PARA_E = cur.var(cx_Oracle.STRING)#返回值

sql_str = "AA.PROC_TEST"

result = cur.callproc(sql_str, [PARA_A, PARA_B, PARA_C, PARA_D, PARA_E])
r = result[-1]
rr = result[-2]
print r
print rr

conn.commit

cur.close
conn.close


#request curl
buffer = BytesIO()
c = pycurl.Curl()
c.setopt(c.URL, 'http://pycurl.sourceforge.net/')
c.setopt(c.WRITEDATA, buffer)
c.perform()
c.close()

body = buffer.getvalue()
# Body is a byte string.
# We have to know the encoding in order to print it to a text file
# such as standard output.
print(body.decode('iso-8859-1'))



